<%@page import="com.xhd.vo.Order"%>
<%@page import="com.xhd.vo.Fruits"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="com.xhd.Dao.SalerDaoImpl"%>
<%@page import="com.xhd.Dao.SalerDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="./css/Inf.css"/>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
        <style type="text/css">
	body {background: rgb(254,238,189);}
</style>
</head>
<body>
<c:if test="${ not empty sessionScope.user}">
<% 
	String fruit = request.getParameter("fruit");
	String buyer = request.getParameter("buyer");
	String sum=request.getParameter("sum");
	String stock=request.getParameter("stock");
	int sumInt=Integer.parseInt(sum);
	int stockInt=Integer.parseInt(stock);
%>
	<%
	SalerDao sd = new SalerDaoImpl();
	sd.changeOrderState("ordersuccess", fruit,buyer);
	sd.FruitSoldOut(fruit, sum, stock);
	
	List<Order> orderlist=sd.showOrderByFruit(fruit);
	Iterator<Order> oIter=orderlist.iterator();
	if(oIter.hasNext()){
		Order order=null;
		while(oIter.hasNext()){
			order=oIter.next();
			if ((order.getOrder_state().equals("待处理")||order.getOrder_state().equals("意向订单")) && Integer.parseInt(order.getOrder_sum())>(stockInt-sumInt) ){
			sd.changeOrderState("out", fruit, order.getOrder_buyer());
			}
		}
		if(!sd.haveOrderOrNot("意向订单")&& (stockInt-sumInt)>0){
			sd.changeFruitState("salefail", fruit);
		}
	}
	%>
		<div id="inf-box">
			<h1>交易成功！</h1>
			
<a href="HistoryMessage.jsp">返回交易页面</a>
		</div>
</c:if>
<c:if test="${  empty sessionScope.user}">
<h1>你还未登录！</h1>
<a href="SalerLogin.jsp">点击登录</a>
</c:if>
</body>
</html>